package com.dayuanit.dy17.library.service.impl;

import com.dayuanit.dy17.library.entity.Book;
import com.dayuanit.dy17.library.exception.BizException;
import com.dayuanit.dy17.library.mapper.BookMapper;
import com.dayuanit.dy17.library.service.IBookService;
import com.dayuanit.dy17.library.util.DBUtils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BookServiceImpl implements IBookService {

    @Autowired
    private BookMapper bookMapper;

    public BookServiceImpl() {
        System.out.println("-----------BookServiceImpl------------");
    }

    @Override
    public List<Book> queryBook(String bookName, String pressName, String authorName) {
        bookName = "".equals(bookName) ? null : bookName;
        pressName = "".equals(pressName) ? null : pressName;
        authorName = "".equals(authorName) ? null : authorName;

        List<Book> books = bookMapper.listBook(bookName, authorName, pressName);
        if (books.isEmpty()) {
            throw new BizException("查无此书");
        }
        return books;
    }
}
